#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <QSystemTrayIcon>
#include <QDateTime>

#include "masterthread.h"
#include "interface.h"

namespace Ui {
    class MainWindow;
}

class MainWindow : public QMainWindow
{
    Q_OBJECT
    
public:
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();

    bool hasMinimizedStartup();

    enum AlarmState {
        AlarmOn,
        AlarmOff
    };
    enum AlarmType {
        AlarmLow,
        AlarmHigh
    };

public slots:
    void onOtherInstanceMessage(const QString &);

protected:
    void closeEvent(QCloseEvent *event);

private slots:
    void exitApplication();
    void about();
    void transaction();
    void showResponse(const QString &s);
    void processError(const QString &s);
    void processTimeout(const QString &s);
    void rdtsime(const long long t);
    void cputime(const long long time);
    void finished();
    void terminated();
    void setSystemTrayIcon();
    void systemTrayActivation(QSystemTrayIcon::ActivationReason reason);
    void editSettings();
    void sendMail();
    void updateProgram();

    void on_actionCheck_for_updates_triggered();

    void on_actionThe_device_triggered();

    void on_actionCalibrate_triggered();

    void on_actionHistory_triggered();

    void on_checkout_spinBox_valueChanged(int arg1);

private:

    void setupPorts();
    void setControlsEnabled(bool enable);
    void readSettings();
    void saveSettings();
    void createTrayActions();
    bool setTemperature(double temp);
    void setAlarm(bool set);
    bool loadUpdatePlugin();
    void setupGraph();
    void setupDatabase();


    int transactionCount;
    int deltaCount;

    double currentTemperature;    
    double deltaTemperature;

    bool mail_ready;

    QSystemTrayIcon *trayIcon;
    QMenu *trayIconMenu;
    QAction *minimizeAction;
    QAction *restoreAction;

    AlarmState alarmState;
    AlarmType alarmType;

    Ui::MainWindow *ui;

    MasterThread thread;

    QDateTime last_msg;

    long long cpu_time;

    UpdMgrInterface* updmgr;

   // QVector<double> time;
   // QVector<double> temp;
};

#endif // MAINWINDOW_H
